package com.itheima.controller;

import com.itheima.manager.SmsCouponManager;
import com.itheima.util.Result;
import com.itheima.vo.SmsCouponVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/coupon")
public class SmsCouponController {

    @Autowired
    SmsCouponManager smsCouponManager;

    //根据优惠券名称和类型分页获取优惠券列表
    @GetMapping("/list")
    public Result list(
            @RequestParam(defaultValue = "1")Integer pageNum,
            @RequestParam(defaultValue = "10")Integer pageSize,
            String name,
            Integer type){
        return smsCouponManager.list(pageNum,pageSize,name,type);
    }
    //添加优惠券
    @PostMapping("/create")
    public Result create(@RequestBody SmsCouponVo couponParam){
        return smsCouponManager.create(couponParam);
    }
    //删除优惠券
    @PostMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        return smsCouponManager.delete(id);
    }
    //修改优惠券
    @PostMapping("/update/{id}")
    public Result update(@PathVariable Integer id,@RequestBody SmsCouponVo couponParam){
        return smsCouponManager.update(id,couponParam);
    }
    //获取单个优惠券的详细信息
    @GetMapping("/{id}")
    public Result selectById(@PathVariable Long id){
        return smsCouponManager.selectById(id);
    }
}
